package com.by.toolkitspring.config;

import jakarta.annotation.PostConstruct;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.common.serialize.hessian2.Hessian2FactoryManager;
import org.apache.dubbo.config.AbstractConfig;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * @author Tian Wei
 * @version 1.0
 * @date 2024/2/4 8:31 PM
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Slf4j
@NoArgsConstructor
@AllArgsConstructor
@Configuration
@AutoConfigureBefore(Hessian2FactoryManager.class)
@ConfigurationProperties(prefix = "dubbo.application.hessian2")
public class Hessian2SerializationConfig extends AbstractConfig {

    private String whitelist;

    private String allow;

    @PostConstruct
    public void loadHessian2White() {
        if (StringUtils.isBlank(whitelist)||StringUtils.isBlank(allow)) {
            return;
        }
        //Hessian2FactoryManager此类中的属性
        System.setProperty("dubbo.application.hessian2.whitelist", whitelist);
        System.setProperty("dubbo.application.hessian2.allow", allow);
        log.info("[Hessian2SerializationConfig][loadHessian2White] Hessian2Serialization load whitelist success,whitelist:{},allow:{}",whitelist,allow);
    }
}
